class Stack {
  constructor() {
    this.count = 0
    this.items = {}
  }
  // 入栈
  push(element) {
    this.items[this.count] = element
    this.count++
  }
  // 出栈
  pop() {
    if (this.isEmpty()) {
      return undefined
    }
    this.count--
    const result = this.items[this.count]
    delete this.items[this.count]
    return result
  }
  // 判空
  isEmpty() {
    return this.count === 0
  }
  // 大小
  size() {
    return this.count
  }
  // 清空
  clear() {
    this.items = {}
    this.count = 0
  }
  // 查看
  peek() {
    if (this.isEmpty()) {
      return undefined
    }
    return this.items[this.size() - 1]
  }
  // 转对象
  toString() {
    return Array.prototype.slice.call(Object.values(this.items))
  }
  // 转数组
  toString() {
    if (this.isEmpty()) {
      return ''
    }
    let objString = `${this.items[0]}`
    for (let i = 1; i < this.count; i++) {
        objString = `${objString}, ${this.items[i]}`
    }
    return objString
  }
}